package main

import (
	"bufio"
	"fmt"
	"io/ioutil"
	"net/http"
	"os"
	"path/filepath"
)

func FileReadLineDo(filepath string, callback func(string)) {
	f, _ := os.Open(filepath)
	defer f.Close()
	scanner := bufio.NewScanner(f)
	for scanner.Scan() {
		callback(scanner.Text())
	}
}

func readDirFiles(dir string) {
	fs, _ := ioutil.ReadDir(dir)
	for _, v := range fs {
		if v.IsDir() {
			readDirFiles(dir + string(filepath.Separator) + v.Name())
			continue
		}

		//fmt.Println("-------------------------",v.Name(),"------------------------")
		// fbs,_ := ioutil.ReadFile(dir + string(filepath.Separator) + v.Name())
		// fmt.Println(string(fbs))

		f, _ := os.Open(dir + string(filepath.Separator) + v.Name())
		defer f.Close()
		scanner := bufio.NewScanner(f)
		for scanner.Scan() {
			fmt.Println(scanner.Text())
		}
	}
}

func httpGet(url string) (string, error) {
	resp, err := http.Get(url)
	if err != nil {
		return "", err
	}

	defer resp.Body.Close()
	bytes, _ := ioutil.ReadAll(resp.Body)
	return string(bytes), nil
}
